<script setup>
import {get} from './utils/axios-request.js'
import router from './router'
import {ElNotification} from "element-plus";
import {onMounted} from "vue";
import MenuHeader from "./views/MenuHeader.vue";

onMounted(() => {
  router.isReady().then(() => {
    let currentRoute = router.currentRoute.value.path
    if (currentRoute !== '/login') {
      let token = localStorage.getItem('token');
      get("/pdf/admin/is/login?token=" + token, isLogin => {
        if (!isLogin) {
          ElNotification({
            title: 'Error',
            message: '您还为登录或登录已失效，请重新登录',
            type: 'error',
            duration: 1000,
            onClose: () => {
              localStorage.clear();
              router.push('/login');
            }
          })
        }
      })
    }
  })
})

</script>

<template>
  <MenuHeader v-if="$route.meta.requiresHeader"/>
  <router-view/>
</template>

<style scoped>

</style>
